package com.yst.hcloud.gw.controller.${packageName};

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.alibaba.fastjson.JSONArray;
import com.hcloud.common.ApiResult;
import com.hcloud.common.Code;
import com.hcloud.common.Constants;
import com.hcloud.exception.ServiceException;
import com.hcloud.page.Page;
import com.hcloud.utils.ConvertDtoUtil;
import com.hcloud.utils.DateDayUtils;
import com.hcloud.utils.StringUtil;

import com.ydcloud.${packageName}.service.${jName}Service;
import com.yst.hcloud.gw.dto.${packageName}.${jName}ListVO;
import com.yst.hcloud.gw.dto.${packageName}.${jName}SaveVO;
import com.yst.hcloud.gw.dto.${packageName}.${jName}DetailVO;
import com.ydcloud.${packageName}.domain.${jName};

/*********************************************************************************************************
 * Copyright (c) 2018
 * All rights reserved.
 *
 * 文件名称:public class ${jName}Controller{ } 
 * 
 * 摘    要： ${jComment}
 * 版    本：1.0
 * 作    者：${createBy}
 * 创建于：${createDate}
 * 最后修改时间：
 * 
*********************************************************************************************************/
@Slf4j
@RestController
@RequestMapping("/admin/sale")
@Api(value = "${jComment}-接口", description = "${jComment}-接口")
public class ${jName}Controller {
	
	@Autowired
	private ${jName}Service ${jPname}Service;
	
	@ApiOperation("${jComment}-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页数", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "String", paramType = "query", required = true),
    })
    @GetMapping(value = "/${jPname}List")
    public ApiResult<Page<${jName}ListVO>> ${jPname}List(@ApiIgnore OAuth2Authentication auth,Integer pageNo,Integer pageSize) throws Exception {
        ApiResult<Page<${jName}ListVO>> result = new ApiResult<Page<${jName}ListVO>>();
        ${jName} ${jPname} =new ${jName}();
        Page<${jName}> query${jName}Page = ${jPname}Service.query${jName}Page(pageSize, pageNo, ${jPname});
        List<${jName}> list=new ArrayList<${jName}>(query${jName}Page.getData());
        List<${jName}ListVO> dataList=ConvertDtoUtil.listBeanToDto(list,${jName}ListVO.class);
		Page<${jName}ListVO> listVo=new Page<${jName}ListVO>(dataList, query${jName}Page.getTotalRecord(), query${jName}Page.getIndex(), query${jName}Page.getSize());
	    result.setData(listVo);
        result.code(Code.normal).message(Constants.YD_OK_SHOW);
        return result;
    } 
    
    @ApiOperation("${jComment}-新增")
    @PostMapping(value = "/add${jName}")
    public ApiResult add${jName}(@ApiIgnore OAuth2Authentication auth,${jName}SaveVO ${jPname}SaveVO) throws Exception {
        ApiResult result = new ApiResult();
        ${jName} ${jPname}=new ${jName}();
        BeanUtils.copyProperties(${jPname}, ${jPname}SaveVO);
        ${jPname}Service.insert(${jPname});
        result.code(Code.normal).message(Constants.YD_OK_SAVE);
        return result;
    }
    
    @ApiOperation("${jComment}-编辑")
    @PostMapping(value = "/edit${jName}")
    public ApiResult edit${jName}(@ApiIgnore OAuth2Authentication auth,${jName}SaveVO ${jPname}SaveVO) throws Exception  {
        ApiResult result = new ApiResult();
        ${jName} ${jPname}=new ${jName}();
        BeanUtils.copyProperties(${jPname}, ${jPname}SaveVO);
        ${jPname}Service.updateByPrimaryKeySelective(${jPname});
        result.code(Code.normal).message(Constants.YD_OK_SAVE);
        return result;
    }
    
    @ApiOperation("${jComment}-详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "${jKey["jName"]}", value = "${jKey["jComment"]}", dataType = "Long", paramType = "query", required = true),
    })
    @PostMapping(value = "/${jPname}Detail")
    public ApiResult<${jName}DetailVO> ${jPname}Detial(@ApiIgnore OAuth2Authentication auth,${jKey["jType"]} ${jKey["jName"]}) throws Exception {
        ApiResult<${jName}DetailVO> result = new ApiResult<${jName}DetailVO>();
        ${jName} ${jPname}= ${jPname}Service.selectByPrimaryKey(${jKey["jName"]});
        ${jName}DetailVO ${jPname}DetailVO=new ${jName}DetailVO();
        BeanUtils.copyProperties(${jPname}DetailVO, ${jPname});
        result.setData(${jPname}DetailVO);
        result.code(Code.normal).message(Constants.YD_OK_SAVE);
        return result;
    }
    
    @ApiOperation("${jComment}-删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "${jKey["jName"]}", value = "${jKey["jComment"]}", dataType = "Long", paramType = "query", required = true),
    })
    @PostMapping(value = "/del${jName}")
    public ApiResult del${jName}(@ApiIgnore OAuth2Authentication auth,${jKey["jType"]} ${jKey["jName"]}) throws Exception {
        ApiResult result = new ApiResult();
        ${jPname}Service.deleteByPrimaryKey(${jKey["jName"]});
        result.code(Code.normal).message(Constants.YD_OK_DELETE);
        return result;
    }
	
}
